<?php

use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
use backend\models\Country;
use kartik\widgets\Select2;
use kartik\widgets\DepDrop;
use yii\helpers\Url;

/* @var $this yii\web\View */
/* @var $model backend\models\PackageEase */
/* @var $form yii\widgets\ActiveForm */


$js = <<<JS
$(function() {
  $("#packageease-principle_suit").blur(function() {
  var principal = $("#packageease-principal").val()
  var principal_suit = $(this).val()
  if(principal_suit>0 && principal>0){
      $("#packageease-percent_principle_suit").val((principal_suit/principal).toFixed(4))
  }
  });
  $("#packageease-principal").blur(function() {
  var principal = $(this).val()
  var principal_suit = $("#packageease-principle_suit").val()
  if(principal_suit>0 && principal>0){
      $("#packageease-percent_principle_suit").val((principal_suit/principal).toFixed(4))
  }
  var price=$("#packageease-price").val()
  if(price>0 && principal>0){
        $("#packageease-discount").val((price/principal).toFixed(4));
    }
  });
  
  $("#packageease-price").blur(function() {
    var price=$(this).val()
    var principal = $("#packageease-principal").val()
    if(price>0 && principal>0){
        $("#packageease-discount").val((price/principal).toFixed(4));
    }
  });
  
})
JS;
$this->registerJs($js);
?>

<div>


</div>
<div class="package-ease-form">
    <?php $form = ActiveForm::begin([
        'id' => 'package-ease-form-id',
        'layout' => 'horizontal',
        'options' => ['class' => ''],
    ]); ?>
    <div class="row">
        <div class="col-sm-offset-2">
            <h4 class="text-success">基本信息</h4>
        </div>
    </div>
    <?= $form->field($model, 'title', ['enableAjaxValidation' => true])->textInput(['maxlength' => true, 'placeholder' => '地区+持包人简称+户数+本金'])->label("<span class='text-danger'>" . $model->getAttributeLabel('title') . '*</span>') ?>
    <?= $form->field($model, 'type')->radioList(Yii::$app->params['package_ease_type'], ['class' => 'form-inline']) ?>
    <?= $form->field($model, 'level')->radioList(Yii::$app->params['package_ease_level'], ['class' => 'form-inline']) ?>
    <?php /*= $form->field($model, 'province')->dropDownList(Country::localCity('`pid`=0 AND `order`>0'), [
        'prompt' => '选择省份',
        'onchange' => '
        $.post("' . Yii::$app->urlManager->createUrl('country/city') . '&typeid=1&pid="+$(this).val(),function(data){$("#packageease-city").html(data);});',
    ])->label("<span class='text-danger'>" . $model->getAttributeLabel('province') . '*</span>') */ ?>


    <?php //= $form->field($model, 'city')->dropDownList(Country::getCityList($model->city), ['prompt' => '选择城市']) ?>
    <?= $form->field($model, 'province')->widget(Select2::className(), ['data' => Country::localCity('`pid`=0 AND `order`>0'),
        'options' => ['placeholder' => '选择省份 ...'],
        'pluginOptions' => [
            'allowClear' => true
        ],]) ?>
    <?php
    echo $form->field($model, 'city')->widget(DepDrop::classname(), [
        'type' => 2,
        'options' => ['multiple' => true],
        'pluginOptions' => [
            'depends' => ['packageease-province'],
            'placeholder' => '选择城市...',
            'url' => Url::to(['/country/get-city', 'province' => 'packageease-province']),
            'allowClear' => true
        ],
    ]);
    ?>

    <?= $form->field($model, 'creditor')->textInput(['maxlength' => true])->label("<span class='text-danger'>" . $model->getAttributeLabel('creditor') . '*</span>') ?>
    <?= $form->field($model, 'principal')->textInput(['maxlength' => true])->label("<span class='text-danger'>" . $model->getAttributeLabel('principal') . '*</span>') ?>
    <?= $form->field($model, 'principle_suit')->textInput(['maxlength' => true,]) ?>
    <?= $form->field($model, 'percent_principle_suit')->textInput(['maxlength' => true, 'disabled' => 'disabled']) ?>
    <?= $form->field($model, 'interest')->textInput(['maxlength' => true]) ?>
    <?= $form->field($model, 'hushu')->textInput(['maxlength' => true])->label("<span class='text-danger'>" . $model->getAttributeLabel('hushu') . '*</span>') ?>
    <?= $form->field($model, 'hushu_suit')->textInput(['maxlength' => true]) ?>
    <?= $form->field($model, 'price')->textInput(['maxlength' => true, 'placeholder' => '当前卖方报价/预估售价']) ?>
    <?= $form->field($model, 'discount')->textInput(['maxlength' => true, 'disabled' => 'disabled']) ?>

    <?= $form->field($model, 'total_mortgage_principal')->textInput(['maxlength' => true, 'placeholder' => '带抵押的项目抵押担保额之和']) ?>

    <?= $form->field($model, 'other_note')->textarea(['row' => 3, 'placeholder' => '说明资产包沟通情况、初步结论等其它补充信息']) ?>
    <?= $form->field($model, 'highlights')->textarea(['placeholder' => '推介理由']) ?>
    <?= $form->field($model, 'follow')->textarea(['placeholder' => '过会信息备注']) ?>
    <?= $form->field($model, 'published_at')->textInput() ?>
    <?= $form->field($model, 'origin')->textInput(['maxlength' => true]) ?>

    <hr>
    <div class="row">
        <div class="col-sm-offset-2">
            <h4 class="text-success">转让信息</h4>
        </div>
    </div>
    <?= $form->field($transferModel, 'method')->radioList(Yii::$app->params['transfer_method'], ['class' => 'form-inline']) ?>
    <?= $form->field($transferModel, 'wish')->textInput() ?>
    <?= $form->field($transferModel, 'detail')->textInput() ?>
    <?= $form->field($transferModel, 'evaluate_transfer_date')->textInput() ?>
    <?= $form->field($transferModel, 'transfer')->radioList(Yii::$app->params['package_ease_transfer'], ['class' => 'form-inline']) ?>
    <?php //= $form->field($transferModel, 'transfer_title')->textInput(['maxlength' => true]) ?>
    <?= $form->field($transferModel, 'contact')->textInput(['maxlength' => true]) ?>
    <?= $form->field($transferModel, 'phone')->textInput(['maxlength' => true]) ?>
    <?= $form->field($transferModel, 'email')->textInput(['maxlength' => true]) ?>
    <?= $form->field($transferModel, 'address')->textInput(['maxlength' => true]) ?>
    <?= $form->field($transferModel, 'position')->textInput(['maxlength' => true]) ?>
    <?= $form->field($transferModel, 'remark')->textarea(['rows' => 3, 'placeholder' => '对本资产包的影响力；居间费用；竞争对手说明；合作模式及其他沟通情况']) ?>
    <div class="row">
        <div class="col-sm-offset-3">
            <div class="form-group">
                <?= Html::submitButton('提交', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
            </div>
        </div>
    </div>
    <?php ActiveForm::end(); ?>

</div>
